<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <title>学生打卡</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <script src="js/jquery-2.1.0.min.js"></script>
    <script type="text/javascript"></script>
    <style>
        html, body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: auto;
        }
        body {
            background: url(images/6.jpg) no-repeat 100% 100%;
            background-size: cover;
        }
    </style>

</head>

<body>
<div id="bar" style="background-color: rgba(0, 0, 0, .4);
    color: #eee;
    display: flex;
    width: 100%;
    height: 60px;
    align-items: stretch;
    justify-content: space-between;
    padding-left: 100px;
    padding-right: 100px;
    margin-bottom: 150px;">
    <div id="bar-left" style="display: flex;
    align-items: center;
    width: 250px;
    justify-content: space-between;" >
        <div id="logo" style = "width: 50px;height: 50px;border-radius: 50%;overflow:hidden;">
            <img src="images/xufe.jpg" style="height: 50px;">
        </div>
        <div id="name" style="font-size:20px">
            学生学习互动系统
        </div>
    </div>
    <div id="bar-right" style="display: flex;
    align-items: center;
    width: 80px;
    justify-content: space-between;">
        <a href="punchlist.html" style="color: #eee;font-size:15px;text-decoration: none;">返回</a>
    </div>
</div>
<div class="container" style="width: 400px;border-top:100px;border-radius: 16px;background-color: rgba(255,255,255,0.8)">
    <h3 style="text-align: center;">学生打卡</h3>
    <div class="form-group">
        <label for="username">学生姓名：</label>
        <input type="text" class="form-control" id="username" name="username" placeholder="请输入登录名"/>
    </div>

    <div class="form-group">
        <label for="loginname">登录名：</label>
        <input type="text" class="form-control" id="loginname" name="loginname" placeholder="请输入姓名"/>
    </div>


    <div class="form-group">
        <label for="reason">打卡方向：</label>
        <input type="text" class="form-control" id="reason" name="reason" placeholder="请输入打卡方向"/>
    </div>


    <div class="form-group" style="text-align: center">
        <input id="btn_sub" class="btn btn-primary" type="button" value="提交" onclick="mysub()"/>
    </div>

</div>
<script>
    // 进行添加操作
    function mysub(){
        var username = jQuery("#username");
        var loginname = jQuery("#loginname");
        var reason = jQuery("#reason").val();

        // 1.非空效验
        if(jQuery.trim(username.val())==""){
            alert("请先输入姓名！");
            username.focus();
            return false;
        }
        if(jQuery.trim(loginname.val())==""){
            alert("请先输入登录名！");
            loginname.focus();
            return false;
        }
        if(jQuery.trim(reason)==""){
            alert("请先输入打卡方向！");
            password.focus();
            return false;
        }
        // 3.将当前的数据提交给后端
        jQuery.ajax({
            url:"punch",
            type:"POST",
            data:{
                "username":username.val(),
                "loginname":loginname.val(),
                "reason":reason,
            },success:function(result){
                if(result!=null && result.data>0){
                    // 添加成功
                    alert("恭喜：打卡成功！");
                    location.href = "punchlist.html";
                }else{
                    alert("打卡失败！只能通过自己的信息打卡！");
                }

            }
        });
    }
</script>
</body>
</html>